package com.changjiang.myproductsale.myproduct.servlet;

import com.changjiang.myproductsale.myproduct.dao.impl.ProductImpl;
import com.changjiang.myproductsale.myproduct.entity.Product;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ServletDetail", value = "/detail")
public class ServletDetail extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收编号
        int id=Integer.parseInt(request.getParameter("id"));
        //调用JDBC查询详情
        Product product=new ProductImpl().queryById(id);
        //带到request中转发到要显示的页面
        System.out.println(product.toString());
        request.setAttribute("product",product);

        request.getRequestDispatcher("/detail.jsp").forward(request,response);
    }
}
